package tech.dort.dortware.impl.modules.exploit;

import com.google.common.eventbus.Subscribe;
import net.minecraft.network.play.client.C03PacketPlayer;
import net.minecraft.potion.Potion;
import tech.dort.dortware.api.module.Module;
import tech.dort.dortware.api.module.ModuleData;
import tech.dort.dortware.api.property.impl.EnumValue;
import tech.dort.dortware.api.property.impl.interfaces.INameable;
import tech.dort.dortware.impl.events.UpdateEvent;
import tech.dort.dortware.impl.utils.networking.PacketUtil;

public class Zoot extends Module {

    private final EnumValue<Zoot.Mode> mode = new EnumValue<>("Mode", this, Zoot.Mode.values());

    public Zoot(ModuleData moduleData) {
        super(moduleData);
        register(mode);
    }

    @Subscribe
    public void onMotion(UpdateEvent event) {
        switch (mode.getValue()) {
            case NORMAL:
                if (event.isPre() && mc.thePlayer.isCollidedVertically) {
                    Potion[] potions = new Potion[]{Potion.blindness, Potion.confusion, Potion.poison, Potion.hunger, Potion.wither};
                    for (Potion potion : potions) {
                        if (mc.thePlayer.isPotionActive(potion)) {
                            mc.thePlayer.removePotionEffect(potion.getId());
                            if (!(potion.equals(Potion.blindness) && potion.equals(Potion.confusion))) {
                                for (int i = 0; i < 50; ++i) {
                                    PacketUtil.sendPacketNoEvent(new C03PacketPlayer.C04PacketPlayerPosition(mc.thePlayer.posX, mc.thePlayer.posY, mc.thePlayer.posZ, true));
                                }
                            }
                            return;
                        }
                    }
                }
                break;
            case HYPIXEL:
                if (event.isPre()) {
                    if (mc.thePlayer.isPotionActive(Potion.jump)) {
                        mc.thePlayer.removePotionEffect(Potion.jump.getId());
                    }
                }
                break;
        }
    }

    public enum Mode implements INameable {
        NORMAL("Normal"), HYPIXEL("Jump Boost");
        private final String name;

        Mode(String name) {
            this.name = name;
        }

        @Override
        public String getDisplayName() {
            return name;
        }
    }
}
